package cn.zwt.wolf.convert;

import cn.zwt.wolf.constant.GlobleConstant;
import cn.zwt.wolf.domain.content.Content;
import cn.zwt.wolf.domain.sync.SyncQueue;
import cn.zwt.wolf.domain.program.OrgProgram;
import cn.zwt.wolf.domain.program.SpiderProgram;
import cn.zwt.wolf.util.CodeIDOperator;

import java.util.Date;

/**
 * Created by zhangwt on 16-3-7.
 */
public class BaseInfoConvert {

    /**
     * orgProgram to content
     * */
    public static  Content convertOrg2Content(OrgProgram orgProgram,Content content){
        if (content == null){
            content = new Content();
            content.setCreateTime(new Date());
            content.setValidTime(new Date());
        }
        if (orgProgram!=null){
            content.setId(orgProgram.getId());
            content.setSid(orgProgram.getSid());
            content.setCode(orgProgram.getCode());
            content.setType(orgProgram.getType());
            content.setOrigin_status(orgProgram.getOrigin_status());
            content.setYear(orgProgram.getYear());
            content.setTitle(orgProgram.getTitle());
            content.setCast(orgProgram.getCast());
            content.setDirector(orgProgram.getDirector());
            content.setActor(orgProgram.getActor());
            content.setHost(orgProgram.getHost());
            content.setInformation(orgProgram.getInformation());
            content.setDuration(orgProgram.getDuration());
            content.setTags(orgProgram.getTags());
            content.setArea(orgProgram.getArea());
            content.setEpstitle(orgProgram.getEpstitle());
            content.setIcon1(orgProgram.getIcon1());
            content.setIcon2(orgProgram.getIcon2());
            content.setIcon3(orgProgram.getIcon3());
            content.setImage1(orgProgram.getImage1());
            content.setImage2(orgProgram.getImage2());
            content.setImage3(orgProgram.getImage3());
            content.setExternalType(orgProgram.getExternalType());
            content.setLanguage(orgProgram.getLanguage());
            content.setScore(orgProgram.getScore());
            content.setEpisode(orgProgram.getEpisode());
            content.setParentId(orgProgram.getParentId());
            content.setCrawTime(orgProgram.getCrawTime());
            content.setDoubanId(orgProgram.getDoubanId());
            content.setStatus(orgProgram.getStatus());
            content.setVideoLengthType(orgProgram.getVideoLengthType());
            content.setMode(orgProgram.getMode());
            content.setUpdateTime(new Date());
            content.setLanguageCode(orgProgram.getLanguageCode());
            content.setAreaCode(orgProgram.getAreaCode());
            content.setTagsCode(orgProgram.getTagsCode());
            content.setContentId(orgProgram.getContentId());
        }
        return content;
    }

    /**
     * 将spiderProgram 转换成　orgProgram
     *
     * */
    public static OrgProgram convertSpiderProgram2OrgProgram(SpiderProgram spiderProgram,OrgProgram orgProgram){
//        OrgProgram orgProgram =orgProgramService.findOrgProgramById(spiderProgram.getId());
        if (orgProgram!=null){
            orgProgram.setType(spiderProgram.getType());
            orgProgram.setOrigin_status(OrgProgram.STATUS_NORMAL);
            orgProgram.setYear(spiderProgram.getYear());
            orgProgram.setTitle(spiderProgram.getTitle());
            orgProgram.setCast(spiderProgram.getCast());
            orgProgram.setDirector(spiderProgram.getDirector());
            orgProgram.setActor(spiderProgram.getActor());
            orgProgram.setHost(spiderProgram.getHost());
            orgProgram.setInformation(spiderProgram.getInformation());
            orgProgram.setDuration(spiderProgram.getDuration());
            orgProgram.setTags(spiderProgram.getTags());
            orgProgram.setArea(spiderProgram.getArea());
            orgProgram.setEpstitle(spiderProgram.getEpstitle());
            orgProgram.setIcon1(spiderProgram.getIcon1());
            orgProgram.setIcon2(spiderProgram.getIcon2());
            orgProgram.setIcon3(spiderProgram.getIcon3());
            orgProgram.setImage1(spiderProgram.getImage1());
            orgProgram.setImage2(spiderProgram.getImage2());
            orgProgram.setImage3(spiderProgram.getImage3());
            orgProgram.setVideoType(spiderProgram.getVideoType());
            orgProgram.setContentType(spiderProgram.getContentType());
            orgProgram.setExternalType(spiderProgram.getExternalType());
            orgProgram.setLanguage(spiderProgram.getLanguage());
            orgProgram.setScore(spiderProgram.getScore());
            orgProgram.setEpisode(spiderProgram.getEpisode());
            orgProgram.setParentId(spiderProgram.getParentId());
            orgProgram.setCrawTime(spiderProgram.getCrawTime());
            orgProgram.setDoubanId(spiderProgram.getDoubanId());
            orgProgram.setStatus(spiderProgram.getStatus());
            orgProgram.setVideoLengthType(spiderProgram.getVideoLengthType());
            orgProgram.setMode(OrgProgram.MODE_AUTO);
            orgProgram.setContentId(spiderProgram.getId());
            /***********************************************/
//            orgProgram.setRank();
//            orgProgram.setRankindex();
        }else {
            orgProgram =new OrgProgram();
            orgProgram.setId(spiderProgram.getId());
            orgProgram.setContentId(spiderProgram.getId());
//            orgProgram.setSid(CodeIDOperator.idToCode(spiderProgram.getId()));
            orgProgram.setType(spiderProgram.getType());
            orgProgram.setOrigin_status(OrgProgram.STATUS_NORMAL);
            orgProgram.setYear(spiderProgram.getYear());
            orgProgram.setTitle(spiderProgram.getTitle());
            orgProgram.setCast(spiderProgram.getCast());
            orgProgram.setDirector(spiderProgram.getDirector());
            orgProgram.setActor(spiderProgram.getActor());
            orgProgram.setHost(spiderProgram.getHost());
            orgProgram.setInformation(spiderProgram.getInformation());
            orgProgram.setDuration(spiderProgram.getDuration());
            orgProgram.setTags(spiderProgram.getTags());
            orgProgram.setArea(spiderProgram.getArea());
            orgProgram.setEpstitle(spiderProgram.getEpstitle());
            orgProgram.setIcon1(spiderProgram.getIcon1());
            orgProgram.setIcon2(spiderProgram.getIcon2());
            orgProgram.setIcon3(spiderProgram.getIcon3());
            orgProgram.setImage1(spiderProgram.getImage1());
            orgProgram.setImage2(spiderProgram.getImage2());
            orgProgram.setImage3(spiderProgram.getImage3());
            orgProgram.setVideoType(spiderProgram.getVideoType());
            orgProgram.setContentType(spiderProgram.getContentType());
            orgProgram.setExternalType(spiderProgram.getExternalType());
            orgProgram.setLanguage(spiderProgram.getLanguage());
            orgProgram.setScore(spiderProgram.getScore());
            orgProgram.setEpisode(spiderProgram.getEpisode());
            orgProgram.setParentId(spiderProgram.getParentId());
            orgProgram.setCrawTime(spiderProgram.getCrawTime());
            orgProgram.setDoubanId(spiderProgram.getDoubanId());
            orgProgram.setStatus(spiderProgram.getStatus());
            orgProgram.setVideoLengthType(spiderProgram.getVideoLengthType());
            orgProgram.setMode(OrgProgram.MODE_AUTO);
            orgProgram.setCreateTime(new Date());
            orgProgram.setCollectTime(new Date());
            orgProgram.setValidTime(new Date());
        }
        return orgProgram;
    }

    /**
     *
     *
     * */
    public static SyncQueue convertSpider2SyncQueue(SpiderProgram spiderProgram,SyncQueue syncQueue){
        if (syncQueue != null){//已经存在相应的队列
            syncQueue.setContentType(spiderProgram.getContentType());
            syncQueue.setContentName(spiderProgram.getTitle());
            syncQueue.setType(spiderProgram.getType());
            syncQueue.setCollectStatus(SyncQueue.COLLECT_STATUS_INITIAL);

        }else {
            syncQueue = new SyncQueue();
            syncQueue.setContentId(spiderProgram.getId());
            syncQueue.setContentSid(CodeIDOperator.idToCode(spiderProgram.getId()));
            syncQueue.setContentType(spiderProgram.getContentType());
            syncQueue.setContentName(spiderProgram.getTitle());
            syncQueue.setType(spiderProgram.getType());
            syncQueue.setQueueContentId(String.valueOf(spiderProgram.getId()));
            syncQueue.setContentType(spiderProgram.getContentType());
            syncQueue.setExternalContentType(spiderProgram.getExternalType());
            syncQueue.setExternalId(String.valueOf(spiderProgram.getId()));
            syncQueue.setStatus(GlobleConstant.STATUS_NORMAL);
            syncQueue.setCollectStatus(SyncQueue.COLLECT_STATUS_INITIAL);
            syncQueue.setEnterStatus(SyncQueue.ENTER_STATUS_INITIAL);
            syncQueue.setPublishStatus(SyncQueue.PUBLISH_STATUS_INITIAL);
            syncQueue.setArrangeStatus(SyncQueue.PUBLISH_ARRANGE_STATUS_INITIAL);
            syncQueue.setPositionStatus(SyncQueue.PUBLISH_POSITION_STATUS_INITIAL);
            syncQueue.setCreatTime(new Date());
        }
        return  syncQueue;
    }
}
